package com.swt.testdemo;

import cn.hutool.core.util.StrUtil;
import com.swt.testdemo.config.ServerConfig;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.boot.builder.SpringApplicationBuilder;
import org.springframework.boot.web.servlet.support.SpringBootServletInitializer;

import javax.annotation.PostConstruct;

/**
 * @author BleethNie
 * @version 1.0
 * @date 2020/11/5 14:05
 **/
@Slf4j
@SpringBootApplication
public class TestdemoApplication extends SpringBootServletInitializer {


    private final ServerConfig serverConfig;

    private static TestdemoApplication app;

    @Autowired
    public TestdemoApplication(ServerConfig serverConfig) {
        this.serverConfig = serverConfig;
    }

    @PostConstruct
    public void init() {
        app = this;
    }

    @Override
    protected SpringApplicationBuilder configure(SpringApplicationBuilder application) {
        return application.sources(TestdemoApplication.class);
    }

    public static void main(String[] args) {
        SpringApplication.run(TestdemoApplication.class, args);
        String address = app.serverConfig.getAddress();
        Integer port = app.serverConfig.getPort();
        if (StrUtil.isBlank(address) || port == null || port == 0) {
            log.error("本程序IP地址或端口号未设置,请在application配置文件中设置,程序将正常退出");
            System.exit(1);
        }
        log.info("swagger-ui地址:  http://{}:{}/doc.html", address, port);
    }
}
